/**
 ******************************************************************************
 * @file    plic.h
 * @author  hyseim software Team
 * @date    12-Mar-2024
 * @brief   
 ******************************************************************************
 * @attention
 * 
 * Copyright (c) 2020 Hyseim. Co., Ltd.
 * All rights reserved.
 * 
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 * 
 ******************************************************************************
 */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __PLIC_H__ 
#define __PLIC_H__ 

#ifdef __cplusplus
 extern "C"{
#endif

/* Includes ------------------------------------------------------------------*/
#include "utils.h"
/** @addtogroup IM110GW_StdPeriph_Driver
  * @{
  */

/** @addtogroup PLIC
  * @{
  */

/** @defgroup PLIC_Exported_Types
  * @{
  */

typedef struct {
    __IO uint32_t PRIORITY[1024];         // 0x000000 - 0x000FFC: Interrupt source 1-1023 priority
    __I uint32_t  PENDING[32];            // 0x001000 - 0x00107C: Interrupt Pending bit 0-1024
         uint32_t RESERVED0[992];
    __IO uint32_t ENABLE[15872][32];      // 0x002000 - 0x1FFFFC: Enable bits for sources 0-1023 on contexts 0-15871
         uint32_t RESERVED1[14336];       
    struct {                    
        __IO uint32_t THRESHOLD;
        union {
            __IO uint32_t CLAIM;
            __IO uint32_t COMPLETE;
        };
        uint32_t RESERVED1[1022];
    } context[15872];                     //0x200000 - 0xFFF004: Interrupt source 1-1023 priority
} PLIC_Type;

#define PLIC                ((PLIC_Type *)          PLIC_BASE)
#define PLIC_NUM_INTERRUPTS     128 

/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
void PLIC_Deinit();
void PLIC_SetPriority(uint32_t irq, uint32_t priority);
uint32_t PLIC_GetPriority(uint32_t irq);
uint32_t PLIC_GetPendingStatus(uint32_t irq);
void PLIC_EnableIRQ(uint32_t irq);
void PLIC_DisableIRQ(uint32_t irq);
void PLIC_SetThreshold(uint32_t threshold);
uint32_t PLIC_GetThreshold();
uint32_t PLIC_GetClaimIRQ();
void PLIC_CompleteIRQ(uint32_t irq);

#ifdef __cplusplus
}
#endif

#endif	/* __PLIC_H__ */
